package com.wzapp.sitposture.authentication.endpoint;

import com.wzapp.sitposture.common.annotation.NeedLogin;
import com.wzapp.sitposture.usercenter.entity.User;
import com.wzapp.sitposture.usercenter.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * 功能: <br/>
 *
 * @author ql
 * @version 0.4
 * @create 2018-05-30 16:47
 **/
@RestController
public class IndexEndpoint {

    //    @Autowired
//    private PasswordEncoder passwordEncoder;
//    @Autowired
//    private Md5PasswordEncoder eigMd5PasswordEncoder;
//    @Autowired
//    private CustomerService customerService;
    @Autowired
    UserRepository userRepository;
//    @Autowired
//    UserService userService;

    @GetMapping("/sayHello")
    public String sayHello() {
        System.out.println("Hello World");
        return "Hello World";
    }

    @GetMapping("/auth/good")
    @PreAuthorize("hasAuthority('query-demo')")
    public String sayHelloToMe() {
        System.out.println("good");
        return "good";
    }

    @GetMapping("/auth/userInfo")
    @NeedLogin
    public User userInfo(Principal principal) {
        System.out.println("good");
        return userRepository.findOne(principal.getName());
    }

    @GetMapping("/user")
    public Principal user(Principal user) {
        System.out.println(user.toString());
        return user;
    }

//    @GetMapping("/bcryptPassword")
//    public String passwordEncoder(String password) {
//        String encode = passwordEncoder.encode(password);
//       boolean t= passwordEncoder.matches(password,"$2a$10$XOVs4Z1YtPKqKwQVywG9j.xLAqXYRQLGZMGMrZDNbtl6pUC0Weteq");
//        System.out.println("匹配："+t);
//        return encode;
//    }
//    @GetMapping("/md5Password")
//    public String md5Password(String password) {
//        String salt = "NqACKgHqCc45rGxMN2iePPX4A2kHRBLt";
//        String encode = eigMd5PasswordEncoder.encodePassword(password, salt);
//        System.out.println("匹配："+encode);
//
////        md5PasswordEncoder.e
//        String onlineMd5 = "0ca175b9c0f726a831d895e269332461";
//        System.out.println(onlineMd5);
//        String myMd5encode =  MD5Util.encrypt(onlineMd5 + salt);
//        System.out.println("匹配："+myMd5encode);
//        System.out.println("匹配：43c0cdceac4fb32d7b4460908bf8167a");
//
//        System.out.println("匹配："+eigMd5PasswordEncoder.encodePassword(password));
//        return encode;
//    }
}
